﻿using System;
using System.Windows.Forms;

namespace Compiler
{
    internal static class Compiler
    {
        public static MainForm mForm1;
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Start();
            Application.Run(mForm1);
        }
        private static void Start()
        {
            mForm1 = new MainForm();
            Production.LoadProductions();
            PredictiveAnalyzeTable.LoadPredictiveAnalyzeTable();
        }
        /// <summary>
        /// 初始化
        /// </summary>
        public static void CompilerInit()
        {
            Token.Init();
            LexicalAnalysis.Init();
            SyntaxAnalysis.Init();
            IntermediateCodeGeneration.Init();
        }
        /// <summary>
        /// 向控制台输出一行内容
        /// </summary>
        public static void WriteLine(string output)
        {
            mForm1.ConsoleAppend(output);
        }
        public static void WriteLine()
        {
            mForm1.ConsoleAppend(string.Empty);
        }
        /// <summary>
        /// 打印异常日志
        /// </summary>
        public static void Log(Exception e)
        {
            mForm1.DebugLog($"-{DateTime.Now} {e.TargetSite} {e.Message}");
        }
    }
}
